#ifndef  __ZeroPopulation_H__
#define  __ZeroPopulation_H__

#include "ZeroEntity.h"
#include "ZeroMutex.h"

class ZeroPopulation {
public:
	ZeroPopulation();
	~ZeroPopulation();

	int getSize();

	void storeEntity(ZeroEntity *entity);
	void merge();
	void reSort();

	ZeroEntity* getEntity(int index);
	ZeroEntity* randomSelect();
	ZeroEntity* prioritySelect(int level);

	void dumpStatus();
private:
	void sort(ZeroEntity **entities, int size);
	void swap(ZeroEntity* &a, ZeroEntity* &b);

	static const int C_DefaultCapacity;
	static const int C_DefaultExpander;

	ZeroEntity **mZEntities;
	ZeroEntity **mNewEntities;

	int mZPopCapacity, mZPopSize;
	int mNewPopCapacity, mNewPopSize;
	
	ZeroMutex *mMutex, *mNewMutex;
};

#endif /*__ZeroPopulation_H__*/
